package com.compty.paint.domain;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.compty.core.framework.context.spring.SpringContextHolder;
import com.compty.paint.manager.PainterManager;
import com.compty.paint.util.Constants;
import com.compty.security.domain.User;

@Entity
@Table(name = "t_special_subject")
public class SpecialSubject {

	private Integer id;
	
	private String title1;
	
	private String title1_color;
	
	private String title2;
	
	private String title2_color;
	
	private String description1;
	
	private String description2;
	
	private String description3;
	
	private String description_color;
	
	private ImageInfo imageInfo;
	
	private String background_color;
	
	private Long painterID;
	
	private String painterName;
	
	private AuditState auditState;
	
	private Date uploadTime;
	
	private Date modifyTime;
	
	private User entryPerson;
	
	private User modifyPerson;
	
	private String channelIDs;//广告发布频道
	
	private String imagepath;//图片路径

	@Id
	@GeneratedValue
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name="title1",length=100)
	public String getTitle1() {
		return title1;
	}

	public void setTitle1(String title1) {
		this.title1 = title1;
	}

	@Column(name="title1_color",length=100)
	public String getTitle1_color() {
		return title1_color;
	}

	public void setTitle1_color(String title1Color) {
		title1_color = title1Color;
	}

	@Column(name="title2",length=100)
	public String getTitle2() {
		return title2;
	}

	public void setTitle2(String title2) {
		this.title2 = title2;
	}

	@Column(name="title2_color",length=100)
	public String getTitle2_color() {
		return title2_color;
	}

	public void setTitle2_color(String title2Color) {
		title2_color = title2Color;
	}

	@Column(name="description1",length=100)
	public String getDescription1() {
		return description1;
	}

	public void setDescription1(String description1) {
		this.description1 = description1;
	}

	@Column(name="description2",length=100)
	public String getDescription2() {
		return description2;
	}

	public void setDescription2(String description2) {
		this.description2 = description2;
	}

	@Column(name="description3",length=100)
	public String getDescription3() {
		return description3;
	}

	public void setDescription3(String description3) {
		this.description3 = description3;
	}

	@Column(name="description_color",length=100)
	public String getDescription_color() {
		return description_color;
	}

	public void setDescription_color(String descriptionColor) {
		description_color = descriptionColor;
	}

	@ManyToOne(fetch = FetchType.LAZY,cascade =  {CascadeType.REMOVE })
	@JoinColumn(name="image_id")
	public ImageInfo getImageInfo() {
		return imageInfo;
	}

	public void setImageInfo(ImageInfo imageInfo) {
		this.imageInfo = imageInfo;
	}

	@Column(name="background_color",length=100)
	public String getBackground_color() {
		return background_color;
	}

	public void setBackground_color(String backgroundColor) {
		background_color = backgroundColor;
	}

	@Column(name="painter_id")
	public Long getPainterID() {
		return painterID;
	}

	public void setPainterID(Long painterID) {
		this.painterID = painterID;
	}
	
	@Column(name="painter_name",length=50)
	public String getPainterName() {
		PainterManager painterManager = SpringContextHolder.getBean("painterManager");
		Painter p = painterManager.get(painterID);
		this.painterName = p.getName();
		return painterName;
	}

	public void setPainterName(String painterName) {
		this.painterName = painterName;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "auditstate_id")
	public AuditState getAuditState() {
		return auditState;
	}

	public void setAuditState(AuditState auditState) {
		this.auditState = auditState;
	}
	
	@Column(name = "uploadtime")
	public Date getUploadTime() {
		return uploadTime;
	}

	public void setUploadTime(Date uploadTime) {
		this.uploadTime = uploadTime;
	}

	@Column(name = "modifytime")
	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="userinfo_id")
	public User getEntryPerson() {
		return entryPerson;
	}

	public void setEntryPerson(User entryPerson) {
		this.entryPerson = entryPerson;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="modify_userinfo_id")
	public User getModifyPerson() {
		return modifyPerson;
	}

	public void setModifyPerson(User modifyPerson) {
		this.modifyPerson = modifyPerson;
	}
	
	@Column(name = "channel_ids",length=10)
	public String getChannelIDs() {
		return channelIDs;
	}

	public void setChannelIDs(String channelIDs) {
		this.channelIDs = channelIDs;
	}
	
	@Transient
	public String getImagepath() {
		if( imageInfo!= null ){
			this.imagepath = Constants.IMAGE_SERVER+Constants.AdvertiseFlag+"/"+imageInfo.getId()+"."+imageInfo.getSuffix();
		}
		else{
			this.imagepath = Constants.IMAGE_SERVER ;
		}
		return imagepath;
	}
	
}
